import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop006_删除订单"

driver = openBrowser(url)
# 调用自定义函数，打开后台网址
driver.get(urlAdmin)
# 输入账号密码 登录后台
DBshopLoginAdmin(driver)
# 进入销售管理订单管理,找到刚才前台提交的订单
# 调用后台的菜单操作函数
DBshopEnterMenu2(driver,'销售管理','订单管理')

# 查询删除前的订单数
s = driver.find_element_by_xpath("//body").text
l = "订单数\："
r = "\)"
num1 = reGetString(s,l,r)

rootPath = get_pro_rootpath() #获取项目的绝对路径
filePath = rootPath+r'\public\order1.txt' #拼接文件路径
orderNo = readFile(filePath) #读取文件中的订单编号

# 在订单号查询框输入orderID，点击“搜索”按钮。
DBshopSearchOrderID(driver,orderNo)
# 勾选，点击删除
driver.find_element_by_xpath("(//input[@name = 'order_id[]'])[1]").click()
driver.find_element_by_xpath("//select[@id = 'allEdit']/option[2]").click()
driver.find_element_by_xpath("(//button[@type = 'submit'])[2]").click()
driver.switch_to.alert.accept()
time.sleep(3)

#删除前的订单数=删除后的订单数+1
s = driver.find_element_by_xpath("//body").text
num2 = reGetString(s,l,r)
if int(num1)==int(num2)+1:
    writeLog("%s 测试通过" % (testCase))
else:
    writeLog("%s 测试失败" % (testCase))
    getPhoto(driver)
driver.quit()